package com.student.dao;

import com.student.entity.Student;
import org.apache.ibatis.annotations.*;

import com.student.entity.Card;
import java.util.List;

@Mapper
public interface StudentMapper  {

    @Results({
            @Result(property = "card", column = "number", one = @One(select = "getCardByNumber"))
    })
//    @Select({
//            "<script>",
//            "SELECT u.*, c.* ",
//            "FROM student u ",
//            "LEFT JOIN card c ON u.number = c.cardNo ",
//            "WHERE 1=1 ",
//            "<if test='name != null and name.trim() != \"\"'>",
//            "AND u.username LIKE CONCAT('%', #{name}, '%')", // 更新列名为username
//            "</if>",
//            "<if test='number != null and number != 0'>",
//            "OR u.number = #{number}",
//            "</if>",
//            "</script>"
//    })
    List<Student> getStuByNameOrNo(@Param("name") String name, @Param("number") Integer number);

    // 根据卡号查询校园卡信息
    @Select("SELECT * FROM card WHERE cardNo = #{number}")
    Card getCardByNumber(@Param("number") Integer number);


}
